<?php
/*
 * 错误日志
 * @package    pre
 * @author     Mark
 * @copyright  Copyright (c) 2013 ixdcw team
 * @version    $Id: 2730601cca21f255c90cb107fdf480c56df25e3a $
 */
class Log {

	/**
	 * 写入到日志位置
	 * @param        $message
	 * @param string $type
	 */
	public static function write($message, $type = 'php') {
		global $DT_IP, $DT_TIME, $_username;
		if (!DT_DEBUG) return;
		$DT_IP or $DT_IP = Env::ip();
		$DT_TIME or $DT_TIME = time();
		$user = $_username ? $_username : 'guest';
		$log  = "<$type>\n";
		$log .= "\t<time>" . date('Y-m-d H:i:s', $DT_TIME) . "</time>\n";
		$log .= "\t<ip>" . $DT_IP . "</ip>\n";
		$log .= "\t<user>" . $user . "</user>\n";
		$log .= "\t<file>" . $_SERVER['SCRIPT_NAME'] . "</file>\n";
		$log .= "\t<querystring>" . str_replace('&', '&amp;', $_SERVER['QUERY_STRING']) . "</querystring>\n";
		$log .= "\t<message>" . $message . "\t</message>\n";
		$log .= "</$type>";
		File::put(DT_ROOT . '/file/log/' . date('Ym', $DT_TIME) . '/' . $type . '-' . date('Y.m.d H.i.s', $DT_TIME) . '-' . strtolower(Str::random(10)) . '.xml', $log);
	}
}